from multiprocessing import Pool
import time
import os


def task():
    print("-----test------")
    print(os.getpid())
    time.sleep(3)


if __name__ == '__main__':
    t1 = time.time()
    p = Pool(3)
    for i in range(0, 3):
        p.apply_async(task)
    print("----start-----")
    p.close()  # 关闭进程池,关闭后p不在接收新的请求
    p.join()  # 等待p中所有子进程执行完毕,必须放在close后面
    print("-----end-----")
    t2 = time.time()
    print('总共花费:', t2 - t1)
